﻿namespace IP_Package.Operations.Neighbor_operations
{
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using FrequencyDomain;

    /// <summary>
    /// edge detection class
    /// </summary>
    public class EdgeDetection : LinearConvolution
    {
        /// <summary>
        /// mask will able it in buffer of image
        /// </summary>
       private Mask mask = new Mask();

       /// <summary>
       /// my detection type
       /// </summary>
       private Detection myDetection;

       /// <summary>
       /// Detection types
       /// </summary>
       public enum Detection
       {
           /// <summary>
           /// point type (Laplacian )
           /// </summary>
           Point,

           /// <summary>
           /// horizontal type in line detection
           /// </summary>
          Horizontal,

           /// <summary>
          /// Vertical type in line detection
           /// </summary>
           Vertical, 

           /// <summary>
           /// right diagonal type in line detection
           /// </summary>
           RightDiagonal,

           /// <summary>
           /// left diagonal type in line detection
           /// </summary>
           LeftDiagonal
       }

       /// <summary>
       /// Gets or sets my detection.
       /// </summary>
       /// <value>
       /// My detection.
       /// </value>
       public Detection MyDetection
       {
           get { return this.myDetection; }
           set { this.myDetection = value; }
       }

       /// <summary>
       /// Makes the edge detection.
       /// </summary>
       /// <returns>the new image</returns>
        public Bitmap MakeEdgeDetection()
        {
            this.mask.MaskSize = 3;
            switch (this.myDetection)
            {
                case Detection.Point:
                    this.mask.MaskValues = new double[,] { { -1, -1, -1 }, { -1, 8, -1 }, { -1, -1, -1 } };
                    break;
                case Detection.Horizontal:
                    this.mask.MaskValues = new double[,] { { 5, -3, -3 }, { 5, 0, -3 }, { 5, -3, -3 } };
                    break;
                case Detection.Vertical:
                    this.mask.MaskValues = new double[,] { { 5, 5, 5 }, { -3, 0, -3 }, { -3, -3, -3 } };
                    break;
                case Detection.RightDiagonal:
                    this.mask.MaskValues = new double[,] { { 5, 5, -3 }, { 5, 0, -3 }, { -3, -3, -3 } };
                    break;
                case Detection.LeftDiagonal:
                   this.mask.MaskValues = new double[,] { { -3, 5, 5 }, { -3, 0, 5 }, { -3, -3, -3 } };
                    break;
                default:
                    break;
            }

            try
            {
                return this.LinearConvolutionFn(this.BufferOfImage, this.mask, "Normalization");
            }
            catch (Exception ex)
            {
                IPPackage.Logger.LogException(ex);
                throw ex;
            }
        }
    }
}
